/** @file bt_debug.c
  *  
  * @brief This file contains functions for displaying HCI Command and
  *        Event name for debugging purpose
  *  
  * (c) Copyright 2003-2008, Marvell International Ltd.
  * All Rights Reserved
  */

#include <windows.h>
#include <ceddk.h>

#ifdef BT_DEBUG
#include "bt_def.h"
#include "bt_dev.h"
#include "bt_func.h"
#include "bt_debug.h"
#include "igxBug.h"

/********************************************************
        Local Variables
********************************************************/

/********************************************************
        Global Variables
********************************************************/

/********************************************************
        Local Functions
********************************************************/

/********************************************************
        Global Functions
********************************************************/

void HCI_EventInfo(PUCHAR buffer,USHORT buffer_len)
{
    unsigned char Event_Type;
    unsigned int OGF_Command;
    unsigned long OCF_Command;
    unsigned long lsize;	

    Event_Type = buffer[0];
    switch (Event_Type)
    {
        case COMMAND_COMPLETE_EVENT:
            OGF_Command = (buffer[4] & 0xFC) >> 2;
            OCF_Command = ((buffer[4] & 0x03) << 8) | buffer[3];
            DBGPRINT(DBG_HCI, (L"HCI_EventInfo:COMMAND_COMPLETE_EVENT: OGF=0x%x: OCF=0x%x \r\n",
                     OGF_Command, OCF_Command));	
	     HexDump(DBG_HCI, "COMMAND_COMPLETE_EVENT BUFFER : ", (PUCHAR)buffer, buffer_len);		
            switch (OGF_Command)
            { 
                case LINK_CONTROL_COMMANDS:  //0x01 
    	            lsize = (unsigned long)sizeof(Link_Control_Command_String)/sizeof(command_mappingg_t); 
    	            if (OCF_Command > lsize)
    	                OCF_Command = lsize - 1;
    	            DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>LINK_CONTROL_COMMANDS: %s\r\n",
                             OGF_Command, OCF_Command,
                             Link_Control_Command_String[OCF_Command].scommand));
    	            break;

    	        case LINK_POLICY_COMMANDS:  //0x02
    	            lsize = (unsigned long)sizeof(Link_Policy_Command_String)/sizeof(command_mappingg_t); 
    	            if (OCF_Command > lsize)
    	                OCF_Command = lsize - 1;
    	            DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>LINK_POLICY_COMMANDS: %s\r\n",
                             OGF_Command, OCF_Command,
                             Link_Policy_Command_String[OCF_Command].scommand));
    	            break;
    	        case CONTROLLER_AND_BASEBAND_COMMANDS:  //0x03
    	            lsize = (unsigned long)sizeof(Controller_And_Baseband_Command_String)/sizeof(command_mappingg_t); 
    	            if (OCF_Command > lsize)
    	                OCF_Command = lsize - 1;
    	            DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>CONTROLLER_AND_BASEBAND_COMMANDS: %s\r\n",
                             OGF_Command, OCF_Command,
                             Controller_And_Baseband_Command_String[OCF_Command].scommand));
    	            break;
    	        case INFORMATIONAL_PARAMETERS:  //0x04
    	            lsize = (unsigned long)sizeof(Informational_Parameters_String)/sizeof(command_mappingg_t); 
    	            if (OCF_Command > lsize)
    	                OCF_Command = lsize - 1;
    	            DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>INFORMATIONAL_PARAMETERS: %s\r\n",
                             OGF_Command, OCF_Command,
                             Informational_Parameters_String[OCF_Command].scommand));
    	            break;
    	        case STATUS_PARAMETERS:  //0x05
    	            lsize = (unsigned long)sizeof(Status_Parameters_String)/sizeof(command_mappingg_t); 
    	            if (OCF_Command > lsize)
    	                OCF_Command = lsize - 1;
    	            DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>STATUS_PARAMETERS: %s\r\n",
                             OGF_Command, OCF_Command,
                             Status_Parameters_String[OCF_Command].scommand));
    	            break;
    	        case TESTING_COMMANDS:  //0x06
    	            lsize = (unsigned long)sizeof(Testing_Commands_String)/sizeof(command_mappingg_t); 
    	            if (OCF_Command > lsize)
    	                OCF_Command = lsize - 1;
    	            DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>TESTING_COMMANDS: %s\r\n",
                             OGF_Command, OCF_Command,
                             Testing_Commands_String[OCF_Command].scommand));
    	            break;
    	        default:
    	            break;
            }  /* switch (OGF_Command) */	  		  	
    	    break; 
        case COMMAND_STATUS_EVENT:
            OGF_Command = (buffer[5] & 0xFC) >> 2;
            OCF_Command = ((buffer[5] & 0x03) << 8) | buffer[4];
            DBGPRINT(DBG_HCI, (L"HIC_EventInfo:COMMAND_STATUS_EVENT: OGF=0x%x: OCF=0x%x \r\n",
                     OGF_Command, OCF_Command));	
	     HexDump(DBG_HCI, "COMMAND_STATUS_EVENT BUFFER : ", (PUCHAR)buffer, buffer_len);		
            switch (OGF_Command)
            { 
                case LINK_CONTROL_COMMANDS:  //0x01 
    	            lsize = (unsigned long)sizeof(Link_Control_Command_String)/sizeof(command_mappingg_t); 
    	            if (OCF_Command > lsize)
    	                OCF_Command = lsize - 1;
    	            DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>LINK_CONTROL_COMMANDS: %s\r\n",
                             OGF_Command, OCF_Command,
                             Link_Control_Command_String[OCF_Command].scommand));
    	            break;

    	        case LINK_POLICY_COMMANDS:  //0x02
    	            lsize = (unsigned long)sizeof(Link_Policy_Command_String)/sizeof(command_mappingg_t); 
    	            if (OCF_Command > lsize)
    	                OCF_Command = lsize - 1;
    	            DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>LINK_POLICY_COMMANDS: %s\r\n",
                             OGF_Command, OCF_Command,
                             Link_Policy_Command_String[OCF_Command].scommand));
    	            break;
    	        case CONTROLLER_AND_BASEBAND_COMMANDS:  //0x03
    	            lsize = (unsigned long)sizeof(Controller_And_Baseband_Command_String)/sizeof(command_mappingg_t); 
    	            if (OCF_Command > lsize)
    	                OCF_Command = lsize - 1;
    	            DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>CONTROLLER_AND_BASEBAND_COMMANDS: %s\r\n",
                             OGF_Command, OCF_Command,
                             Controller_And_Baseband_Command_String[OCF_Command].scommand));
    	            break;
    	        case INFORMATIONAL_PARAMETERS:  //0x04
    	            lsize = (unsigned long)sizeof(Informational_Parameters_String)/sizeof(command_mappingg_t); 
    	            if (OCF_Command > lsize)
    	                OCF_Command = lsize - 1;
    	            DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>INFORMATIONAL_PARAMETERS: %s\r\n",
                             OGF_Command, OCF_Command,
                             Informational_Parameters_String[OCF_Command].scommand));
    	            break;
    	        case STATUS_PARAMETERS:  //0x05
    	            lsize = (unsigned long)sizeof(Status_Parameters_String)/sizeof(command_mappingg_t); 
    	            if (OCF_Command > lsize)
    	                OCF_Command = lsize - 1;
    	            DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>STATUS_PARAMETERS: %s\r\n",
                             OGF_Command, OCF_Command,
                             Status_Parameters_String[OCF_Command].scommand));
    	            break;
    	        case TESTING_COMMANDS:  //0x06
    	            lsize = (unsigned long)sizeof(Testing_Commands_String)/sizeof(command_mappingg_t); 
    	            if (OCF_Command > lsize)
    	                OCF_Command = lsize - 1;
    	            DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>TESTING_COMMANDS: %s\r\n",
                             OGF_Command, OCF_Command,
                             Testing_Commands_String[OCF_Command].scommand));
    	            break;
    	        default:
    	            break;
            }  /* switch (OGF_Command) */	  		  	
    	    break; 
			
	default:
	  break;		
    }  /* switch (Event_Type) */  
}

void HCI_CommandInfo(unsigned char *buffer)
{
    unsigned int OGF_Command;
    unsigned long OCF_Command;
    unsigned long lsize;
   
    OGF_Command = ((buffer[1] & 0xFC) >> 2);
    OCF_Command = ((buffer[1] & 0x03) << 8) | buffer[0];

    DBGPRINT(DBG_HCI, (L"HCI_CommandInfo: OGF=0x%x: OCF=0x%x \r\n",
             OGF_Command, OCF_Command));	
    switch (OGF_Command)
    {
        case LINK_CONTROL_COMMANDS:  //0x01 
    	    lsize = (unsigned long )sizeof(Link_Control_Command_String)/sizeof(command_mappingg_t); 
    	    if (OCF_Command > lsize)
    	        OCF_Command = lsize - 1;
    	    DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>LINK_CONTROL_COMMANDS: %s\r\n",
                     OGF_Command, OCF_Command,
                     Link_Control_Command_String[OCF_Command].scommand));
    	    break;
    	case LINK_POLICY_COMMANDS:  //0x02
    	    lsize = (unsigned long)sizeof(Link_Policy_Command_String)/sizeof(command_mappingg_t); 
    	    if (OCF_Command > lsize)
    	        OCF_Command = lsize - 1;
    	    DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>LINK_POLICY_COMMANDS: %s\r\n",
                     OGF_Command, OCF_Command,
                     Link_Policy_Command_String[OCF_Command].scommand));
    	    break;
    	case CONTROLLER_AND_BASEBAND_COMMANDS:  //0x03
    	    lsize = (unsigned long)sizeof(Controller_And_Baseband_Command_String)/sizeof(command_mappingg_t); 
    	    if (OCF_Command > lsize)
    	        OCF_Command = lsize - 1;
    	    DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>CONTROLLER_AND_BASEBAND_COMMANDS: %s\r\n",
                     OGF_Command, OCF_Command,
                     Controller_And_Baseband_Command_String[OCF_Command].scommand));
    	    break;
    	case INFORMATIONAL_PARAMETERS:  //0x04
    	    lsize = (unsigned long)sizeof(Informational_Parameters_String)/sizeof(command_mappingg_t); 
    	    if (OCF_Command > lsize)
    	        OCF_Command = lsize - 1;
    	    DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>INFORMATIONAL_PARAMETERS: %s\r\n",
                     OGF_Command, OCF_Command,
                     Informational_Parameters_String[OCF_Command].scommand));
    	    break;
    	case STATUS_PARAMETERS:  //0x05
    	    lsize = (unsigned long)sizeof(Status_Parameters_String)/sizeof(command_mappingg_t); 
    	    if (OCF_Command > lsize)
    	        OCF_Command = lsize - 1;
    	    DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>STATUS_PARAMETERS: %s\r\n",
                     OGF_Command, OCF_Command,
                     Status_Parameters_String[OCF_Command].scommand));
    	    break;
    	case TESTING_COMMANDS:  //0x06
    	    lsize = (unsigned long)sizeof(Testing_Commands_String)/sizeof(command_mappingg_t); 
    	    if (OCF_Command > lsize)
    	        OCF_Command = lsize - 1;
    	    DBGPRINT(DBG_HCI, (L"0x%x: 0x%x =>TESTING_COMMANDS: %s\r\n",
                     OGF_Command, OCF_Command,
                     Testing_Commands_String[OCF_Command].scommand));
    	    break;
    	default:
    	    break;
    }  /* switch (OGF_Command) */
}

#endif //BT_DEBUG
